#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tkinter import *
import threading
from serial_hanlde import logic  # 调用b文件中的logic类


class Ymodem_Gui:
    def __init__(self):
        self.window  = Tk()
        self.window.title('Ymodem串口烧录工具')
        # self.window .iconbitmap(default='download.ico')
        self.window.geometry("800x600+500+200")
        self.window["background"] = "#C9C9C9"
        self.interface()

    def interface(self):

        self.label_cv = Canvas(self.window, bg="#778882")
        self.label_cv.create_rectangle(110,110,110,110)
        self.label_ports = Label(self.label_cv , text="COM端口：", font=("微软雅黑", 16), bg="#778882")
        self.label_ports.grid(row=1, column=1, sticky=E)
        self.label_bound = Label(self.label_cv , text="波特率：", font=("微软雅黑", 16), bg="#778882")
        self.label_bound.grid(row=2, column=1, sticky=E)
        self.label_databit = Label(self.label_cv , text="数据位：", font=("微软雅黑", 16), bg="#778882")
        self.label_databit.grid(row=3, column=1, sticky=E)
        self.label_stopbit = Label(self.label_cv , text="停止位：", font=("微软雅黑", 16), bg="#778882")
        self.label_stopbit.grid(row=4, column=1, sticky=E)
        self.label_checkbit = Label(self.label_cv , text="校验位：", font=("微软雅黑", 16), bg="#778882")
        self.label_checkbit.grid(row=5, column=1, sticky=E)
        # self.Button0 = tk.Button(self.window , text="连接", command=self.start, bg="#7bbfea")
        # self.label_ports.grid(row=6, column=6, sticky=E)
        self.label_cv.pack()
    def seal(self):
        '''把b文件的类单独写一个方法'''
        a = self.entry00.get()
        w1 = self.w1
        logic().event(a, w1)

    def start(self):
        '''子线程无法直接执行b的类，需要把b文件单独写一个方法，然后执行'''
        self.T = threading.Thread(target=self.seal)
        self.T.setDaemon(True)
        self.T.start()

